package com.erpanderp.wam.web;

import org.restlet.data.MediaType;
import org.restlet.data.Status;
import org.restlet.representation.Representation;
import org.restlet.representation.StringRepresentation;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;

import com.erpanderp.wam.usm.model.entity.user.Employee;
import com.erpanderp.wam.usm.model.service.user.EmployeeDAO;

public class WAMUserResource extends ServerResource {

	@Get("xml")
	public Representation getXML() {
		String userCode = (String) getRequest().getAttributes().get("ucode");
		Employee employee = new EmployeeDAO().getEmployeeByEmployeeCode(userCode);
		if(employee == null) {
			setStatus(Status.CLIENT_ERROR_NOT_FOUND);
			return null;
		}
		
		StringBuffer sb = new StringBuffer("<employee>");
		sb.append("<employeecode>");
		sb.append(employee.getEmployeeCode());
		sb.append("</employeecode>");
		sb.append("<firstname>");
		sb.append(employee.getFirstName());
		sb.append("</firstname>");
		sb.append("<lastname>");
		sb.append(employee.getLastName());
		sb.append("</lastname>");
		sb.append("<designation>");
		sb.append(employee.getDesignation());
		sb.append("</designation>");
		sb.append("<module>");
		sb.append(employee.getModuleName());
		sb.append("</module>");
		sb.append("<email>");
		sb.append(employee.getEmail());
		sb.append("</email>");
		sb.append("<mobile>");
		sb.append(employee.getTelephone());
		sb.append("</mobile>");
		sb.append("</employee>");
		return new StringRepresentation(sb, MediaType.APPLICATION_XML);
	}

}